package com.huaao.micropolice.core.common.page;

import org.apache.commons.lang3.StringUtils;

public class Parameter {
	
	public String field;
	
	public String sign;
	
	public Object value;
	
	public String ops = "AND";
	
	public Parameter(){}
	
	public Parameter(String params){
		if(StringUtils.isNotBlank(params)){
			String[] array = params.split("_");
			if(array.length>0){
				field = array[0];
			}
			if(array.length>1){
				sign = array[1];
			}
			if(array.length>2){
				value = array[2];
			}
			if(array.length>3){
				ops = array[3];
			}
		}
	}
	
	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}

	public String getOps() {
		return ops;
	}

	public void setOps(String ops) {
		this.ops = ops;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
	}
	
	public String getHql(){
		StringBuffer buffer = new StringBuffer(" "+ops+" "+field);
		if("eq".equalsIgnoreCase(sign)){
			buffer.append(" = '"+value.toString()+"'");
		}else if("ne".equalsIgnoreCase(sign)){
			buffer.append(" != '"+value.toString()+"'");
		}else if("lt".equalsIgnoreCase(sign)){
			buffer.append(" < '"+value.toString()+"'");
		}else if("le".equalsIgnoreCase(sign)){
			buffer.append(" <= '"+value.toString()+"'");
		}else if("gt".equalsIgnoreCase(sign)){
			buffer.append(" > '"+value.toString()+"'");
		}else if("ge".equalsIgnoreCase(sign)){
			buffer.append(" >= '"+value.toString()+"'");
		}else if("lk".equalsIgnoreCase(sign)){
			buffer.append(" like '"+value.toString()+"%'");
		}else if("bn".equalsIgnoreCase(sign)){
			buffer.append(" not like '"+value.toString()+"%'");
		}else if("in".equalsIgnoreCase(sign)){
			buffer.append(" in ("+value.toString()+")");
		}else if("ni".equalsIgnoreCase(sign)){
			buffer.append(" not in ("+value.toString()+")");
		}else if("ew".equalsIgnoreCase(sign)){
			buffer.append(" like '%"+value.toString()+"'");
		}else if("en".equalsIgnoreCase(sign)){
			buffer.append(" not like '%"+value.toString()+"'");
		}else if("cn".equalsIgnoreCase(sign)){
			buffer.append(" like '%"+value.toString()+"%'");
		}else if("nc".equalsIgnoreCase(sign)){
			buffer.append(" not like '%"+value.toString()+"%'");
		}else if("is".equalsIgnoreCase(sign)){
			buffer.append(" is null ");
		}
		return buffer.toString();
	}
}
